import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;

import java.util.Arrays;
import java.util.List;
import java.util.Set;

/**
 * @Author lzc
 * @Date 2022/7/16 15:37
 */
public class Demo2 {
    public static void main(String[] args) {
        JSONObject data = JSON.parseObject("{\"tm_name\":\"TCL\",\"operate_type\":\"bootstrap-insert\",\"logo_url\":\"/static/default.jpg\",\"id\":4}");
        List<String> columns = Arrays.asList("id,tm_name".split(","));
    
    
        Set<String> keys = data.keySet();
        /*for (String key : keys) {  // 不能这么删
            if (!columns.contains(key) && !key.equals("operate_type")) {
                keys.remove(key);
            }
        }*/
        
        /*while (it.hasNext()) {
            String key = it.next();
            if (!columns.contains(key) && !key.equals("operate_type")) {
                it.remove();
            }
        }*/
        keys.removeIf(key -> !columns.contains(key) && !key.equals("operate_type"));
        System.out.println(data);
    
    
    }
}
